<include file="public@header"/>
<style>
    .data-item-tr, .search-btn {
        cursor: pointer;
    }
    .row{margin:0;}
    .col-xs-3 {
        padding: 0;
        width:auto;
    }
    .sr-only {display: none;}
</style>
</head>
<body>
<div class="layui-fluid js-check-wrap">
    <div class="layui-card">
        <notempty name="filters">
            <div class="layui-card-body">
                <form method="post" action="{:url('theme/dataSource')}" id="search-form" class="layui-form form-search layui-form layui-form-item">

                    <div class="row">

                        <foreach name="filters" item="filter" key="filterName">
                            <switch name="filter.type">
                                <case value="text">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">{$filter.title|default=''}</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" name="{$filterName}"
                                                   placeholder="{$filter.placeholder|default=''}"
                                                   value="{$form[$filterName]|default=''}">
                                            </div>
                                        </div>
                                </case>
                                <case value="select">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">{$filter.title|default=''}</label>
                                            <div class="layui-input-inline">
                                                <select name="{$filterName}">
                                                    <notempty name="filter.placeholder">
                                                        <option value="">{$filter.placeholder|default=''}</option>
                                                    </notempty>
                                                    <foreach name="filter.options" item="option">
                                                        <php>
                                                            $option_selected='';
                                                            if(isset($form[$filterName]) &&  $form[$filterName]==$option['id']){
                                                                $option_selected='selected';
                                                            };
                                                        </php>
                                                        <option value="{$option.id}" {$option_selected}>{$option.name}</option>
                                                    </foreach>
                                                </select>
                                            </div>
                                        </div>
                                </case>
                            </switch>
                        </foreach>
                            
                        <input type="hidden" value="{$data_source}" name="data_source">
                        <input type="hidden" value="{:implode(',',$selected_ids)}" name="ids">
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-normal">搜索</button>
                        </div>
                        <!-- <a class="layui-btn layui-btn-danger layui-btn-sm" href="{:url('theme/dataSource')}?data_source={$data_source}">清空</a> -->
                    </div>

                    <!--<div class="layui-form-item">-->
                    <!--<div class="input-group">-->
                    <!--<input type="text" class="layui-input" name="keyword" value="{$keyword|default=''}"-->
                    <!--placeholder="请输入关键字">-->
                    <!--<input type="hidden" value="{$data_source}" name="data_source">-->
                    <!--<span class="input-group-addon search-btn" onclick="submitSearchForm()">GO!</span>-->
                    <!--</div>-->
                    <!--</div>-->
                </form>
            </div>
        </notempty>

        <form method="post" class="js-ajax-form">
            <table class="layui-table">
                <thead>
                <tr>
                    <th width="16">
                        <if condition="$multi">
                                <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                        </if>
                    </th>
                    <th width="50">ID</th>
                    <th>名称</th>
                </tr>
                </thead>
                <tbody>
                {$items_tree}
                </tbody>
            </table>
        </form>
    </div>
</div>
<include file="public@footer"/>
<script>
    $('.data-item-tr').click(function (e) {
        var $this = $(this);
        if ($(e.target).is('input')) {
            return;
        }

        var $input = $this.find('input');
        if ($input.is(':checked')) {
            $input.prop('checked', false);
        } else {
            $input.prop('checked', true);
        }
    });

    function submitSearchForm() {
        $('#search-form').get(0).submit();
    }

    function confirm() {
        var selectedObjectsId   = [];
        var selectedObjectsName = [];
        var selectedObjects     = [];
        $('.js-select-box:checked').each(function () {
            var $this = $(this);
            selectedObjectsId.push($this.val());
            selectedObjectsName.push($this.data('name'));

            selectedObjects.push({
                id: $this.val(),
                name: $this.data('name')
            });
        });

        return {
            selectedObjects: selectedObjects,
            selectedObjectsId: selectedObjectsId,
            selectedObjectsName: selectedObjectsName
        };
    }
</script>
